package com.example.userdome.controller;

import com.example.userdome.pojo.Article;
import com.example.userdome.pojo.Like;
import com.example.userdome.service.impl.ArticleServiceImpl;
import com.example.userdome.service.impl.LikeServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/articles")
public class ArticleSystemController {
    @Resource
    private LikeServiceImpl likeService;
    //点赞
    @PostMapping("/add")
    public boolean addLike(@RequestBody Like like){
        return likeService.addLike(like);
    }
    //取消点赞
    @PostMapping("/cancel")
    public boolean cancelLike(@RequestBody Like like){
        return likeService.cancelLike(like);
    }
    //所有文章加起来的总点赞
    @GetMapping("/count")
    public int countLike(@RequestParam int articleid){
        return likeService.countLikes(articleid)+1;
    }
    @Resource
    private ArticleServiceImpl articleService;

    //根据文章的id来给出文章的获赞数
    @GetMapping("/likecount")
    public List<Article> getArticlesWithLikeCount(){
        return articleService.getArticlesWithLikeCount();
    }
}
